﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

public partial class UserProfile : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!HttpContext.Current.Request.IsAuthenticated)
        {
            Response.Redirect("~/login.aspx");
        }
        else
        {
            if (!Page.IsPostBack)
            {



                    //Create Connection String And SQL Statement
                    string strConnection = ConfigurationManager.ConnectionStrings["stockmarketConnectionString"].ConnectionString;

                    SqlConnection sqlConnection = new SqlConnection(strConnection);

                    string findUserProfile = "SELECT UserName, FirstName, LastName, Contact,LastLoginDate, EmailAddress, Nationality, Occupation, Company, AccountAmount, ReferalCode FROM [User] where UserName ='" + User.Identity.Name + "'";

                    SqlCommand command1 = new SqlCommand(findUserProfile, sqlConnection);

                    sqlConnection.Open();

                    command1.ExecuteNonQuery();

                    //Fill the fields into a dataset and display onto the label text.
                    DataSet dsPwd = new DataSet();
                    SqlDataAdapter dAdapter = new SqlDataAdapter(command1);

                    dAdapter.Fill(dsPwd);


                    Label1.Text = dsPwd.Tables[0].Rows[0]["Username"].ToString();
                    Label2.Text = dsPwd.Tables[0].Rows[0]["FirstName"].ToString();
                    Label3.Text = dsPwd.Tables[0].Rows[0]["LastName"].ToString();
                    Label4.Text = dsPwd.Tables[0].Rows[0]["Nationality"].ToString();

                    Label6.Text = dsPwd.Tables[0].Rows[0]["EmailAddress"].ToString();
                    Label7.Text = dsPwd.Tables[0].Rows[0]["Contact"].ToString();
                    Label8.Text = dsPwd.Tables[0].Rows[0]["Occupation"].ToString();
                    Label9.Text = dsPwd.Tables[0].Rows[0]["Company"].ToString();
                    Label10.Text = dsPwd.Tables[0].Rows[0]["AccountAmount"].ToString();
                    Label111.Text = dsPwd.Tables[0].Rows[0]["ReferalCode"].ToString();

                    sqlConnection.Close();

                string user = (string)(Session["Userfield"]);

                if (user == "admin")
                {
                    AdminHyperLink1.Visible = true;

                }
                else
                {
                    AdminHyperLink1.Visible = false;

                }

               
                
            }

        }

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        
    }
    protected void Button3_Click(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

    }
}